<template>
  <div id="app">
    <img alt="Vue logo" src="./assets/logo.png">
    <el-table
        :class="{'header-fix': headerFox}"
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          prop="date"
          label="日期"
          width="180">
      </el-table-column>
      <el-table-column
          prop="name"
          label="姓名"
          width="180">
      </el-table-column>
      <el-table-column
          prop="address"
          label="地址">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      headerFox: false,
      tableData: []
    }
  },
  beforeMount() {
    window.addEventListener('scroll', this.scrollEvent)
  },
  beforeDestroy() {
    window.removeEventListener('scroll', this.scrollEvent)
  },
  mounted() {
    for (let i = 1; i < 1000; i++) {
      this.tableData.push({
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 ' + i + ' 弄'
      })
    }
  },
  methods: {
    scrollEvent() {
      const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
      console.log('1111', scrollTop)
      this.headerFox = scrollTop >= 260
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

.header-fix {
  .el-table__header-wrapper {
    top: 3px;
    position: fixed !important;
    z-index: 99;
  }
}
</style>
